package com.csdj.questions.mapper;

import com.baomidou.mybatisplus.core.mapper.Mapper;
import com.csdj.questions.entity.Answer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.csdj.questions.entity.Article;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 回答表 Mapper 接口
 * </p>
 *
 * @author 刘宇
 * @since 2022-03-08
 */
public interface AnswerMapper extends BaseMapper<Answer> {
    /**
     *  连表模糊查询，answer 和 t_question 和 article  的连表
     * @return
     */
    @Select("SELECT q.ques_id,q.ques_name,a.snswer_content,q.create_time,q.attention_numb\n" +
            "FROM answer AS a\n" +
            "JOIN t_question AS q\n" +
            "ON q.ques_id = a.ques_id\n" +
            "join article AS c\n" +
            "ON a.ques_id = c.ques_Id\n" +
            "WHERE q.ques_name LIKE concat(#{quesName},'%') OR c.article_name LIKE concat(#{articleName}," +
            "'%')")

    public List<Map<String,Object>> selectLike(String quesName,String articleName);

    /**
     * 根据问题id 查询 点赞的次数
     * @param quesId
     * @return
     */
    @Select("SELECT COUNT(ques_id)\n" +
            "    FROM attques_comment\n" +
            "    WHERE ques_id = #{quesId}")
    public int selectCount(String quesId);

}
